
<template>
    <p>name: {{name}}, age: {{age}}</p>
    <el-button @click="postMsg">子组件发送事件</el-button>
</template>

<script>
import { ref, toRefs } from 'vue'

export default {
  name: 'ToRefSon',
  emits: ['pMsg'], // 处理控制台报错
  props: {
    name: {
      type: String,
      default: ''
    }
  },
  setup (props, { attrs, emit, slot }) {
    const { name } = toRefs(props)
    const age = ref(attrs.age)
    console.log('name, age', name, age)
    console.log('attrs,emit,slot', attrs, emit, slot)
    const postMsg = () => {
      emit('pMsg', '发送事件')
    }
    return {
      age,
      postMsg
    }
  }
}

</script>
